package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.TrainingReservation;
import com.ruoyi.training.service.ITrainingReservationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 培训预约记录Controller
 *
 * @author WorrilessGo
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/TrainingReservation")
public class TrainingReservationController extends BaseController
{
    @Autowired
    private ITrainingReservationService trainingReservationService;

    /**
     * 查询培训预约记录列表
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainingReservation trainingReservation)
    {
        startPage();
        List<TrainingReservation> list = trainingReservationService.selectTrainingReservationList(trainingReservation);
        return getDataTable(list);
    }

    /**
     * 导出培训预约记录列表
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:export")
    @Log(title = "培训预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingReservation trainingReservation)
    {
        List<TrainingReservation> list = trainingReservationService.selectTrainingReservationList(trainingReservation);
        ExcelUtil<TrainingReservation> util = new ExcelUtil<TrainingReservation>(TrainingReservation.class);
        util.exportExcel(response, list, "培训预约记录数据");
    }

    /**
     * 获取培训预约记录详细信息
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:query")
    @GetMapping(value = "/{trainingReservationId}")
    public AjaxResult getInfo(@PathVariable("trainingReservationId") String trainingReservationId)
    {
        return success(trainingReservationService.selectTrainingReservationByTrainingReservationId(trainingReservationId));
    }

    /**
     * 新增培训预约记录
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:add")
    @Log(title = "培训预约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingReservation trainingReservation)
    {
        return toAjax(trainingReservationService.insertTrainingReservation(trainingReservation));
    }

    /**
     * 修改培训预约记录
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:edit")
    @Log(title = "培训预约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingReservation trainingReservation)
    {
        return toAjax(trainingReservationService.updateTrainingReservation(trainingReservation));
    }

    /**
     * 删除培训预约记录
     */
    @RequiresPermissions("TrainingReservation:TrainingReservation:remove")
    @Log(title = "培训预约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainingReservationIds}")
    public AjaxResult remove(@PathVariable String[] trainingReservationIds)
    {
        return toAjax(trainingReservationService.deleteTrainingReservationByTrainingReservationIds(trainingReservationIds));
    }
}
